package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.bean.Orders;
import com.itheima.dao.OrdersDao;
import com.itheima.dto.PageParemDto;
import com.itheima.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersDao ordersDao;
    @Override
    public IPage<Orders> findpage(PageParemDto pageParemDto) {
        IPage<Orders> page = new Page<>(pageParemDto.getPage(),pageParemDto.getPageSize());
        LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
        lqw.eq(pageParemDto.getNumber()!=null,Orders::getNumber,pageParemDto.getNumber());
        lqw.ge(pageParemDto.getBeginTime()!=null,Orders::getOrderTime,pageParemDto.getBeginTime());
        lqw.le(pageParemDto.getEndTime()!=null,Orders::getOrderTime,pageParemDto.getEndTime());
        return ordersDao.selectPage(page, lqw);
    }

    @Override
    public int UpdateStatus(Orders orders) {
        Orders orders1 = ordersDao.selectById(orders.getId());
        orders1.setStatus(orders.getStatus());
        return ordersDao.updateById(orders1);
    }
}
